package vn.edu.fpt.xml.back.utils;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by hiephn on 2014/04/28.
 */
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {

    public static final String RSS_TIMESTAMP_PATTERN = "EEE, d MMM yyyy hh:mm:ss Z"; // Mon, 28 Apr 2014 11:02:12 +0700
    public static final String XN_CLOUD_DATETIME_SIMPLE_FORMAT_FOR_DISPLAY_PATTERN = "hh:mm dd/MM/yyyy";

    public Timestamp toTimestamp(String dateString, String pattern) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        Date date = simpleDateFormat.parse(dateString);

        Timestamp timestamp = new Timestamp(date.getTime());
        return timestamp;
    }

    public String toString(Timestamp timestamp, String pattern) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        String format = simpleDateFormat.format(new Date(timestamp.getTime()));
        return format;
    }
}
